#pragma once

#include "StringUtils.h"
#include <map>


typedef std::map<std::string, std::string> SSMap;


class IObject
{
public:
	virtual void SetAttribute(const std::string& name, const std::string& value)
	{
		m_Attributes[name] = value;
	}
	
	std::string GetAttribute(const std::string& name)
	{
		auto it = m_Attributes.find(name);
		if (it==m_Attributes.end())
		{
			return "";
		}

		return it->second;
	}

	const SSMap& GetAttributeList()
	{
		return m_Attributes;
	}

private:
	SSMap m_Attributes;
};


class IControl : public IObject
{
public:
	void SetAttribute(const std::string& name, const std::string& value)
	{
		IObject::SetAttribute(name, value);

		OnSetAttribute(name, value);
	}

protected:
	virtual void OnSetAttribute(const std::string& name, const std::string& value)
	{
		printf("IControl: %s = %s \n", name.c_str(), value.c_str());

	}
};


class IButton : public IControl
{
public:

protected:
	void OnSetAttribute(const std::string& name, const std::string& value)
	{
		if (name=="normal")
		{
			printf("IButton: %s = %s \n", name.c_str(), value.c_str());
		}
		else
		{
			IControl::OnSetAttribute(name, value);
		}

		//IObject::OnSetAttribute(name, value);
	}

};


class Window
{
public:
	void Init()
	{
		m_pRootControl = new IButton();
		assert(m_pRootControl);

		SSMap attributes = { {"pos", "1,1,1,1"},
							 {"name","btn_test"},
							 {"text", "OK"},
							 {"normal","D:test.image"} };

		for (auto attr : attributes)
		{
			m_pRootControl->SetAttribute(attr.first, attr.second);
		}
	}

private:
	IControl* m_pRootControl;

};

void test_Inherit()
{
	Window wnd;

	wnd.Init();
}